import {createRouter,createWebHashHistory,RouteRecordRaw,Router} from 'vue-router'
import frontRoutes from '@/router/front'
import adminRoutes from '@/router/admin'
import {checkUserIsAdmin} from '@/api/admin/index'
const routes:RouteRecordRaw[] = [
    ...frontRoutes,
    ...adminRoutes
]

const router:Router = createRouter({
    history:createWebHashHistory(),
    routes
})
router.beforeEach(async (to,from,next) =>{
    if (to.path.indexOf('admin') != -1){
        let data:any = await checkUserIsAdmin()
        if (data.code == 200){
            next()
            return
        }
        console.log(data.code,data.err_msg)
        next({path:'/'})
        return
    }
    next()

})
export default router